"""
    Desc 加密解密工具类

    @author tinaroot.cn
    @time 2022/3/5 16:41
"""
import binascii
from pyDes import des, CBC, PAD_PKCS5


def des_encrypt(secretKey, content):
    """
    加密
    :param secretKey: 加密KEY
    :param content:  加密内容
    :return:  16进制内容
    """
    iv = secretKey
    k = des(secretKey, CBC, iv, pad=None, padmode=PAD_PKCS5)
    en = k.encrypt(content, padmode=PAD_PKCS5)
    return (binascii.b2a_hex(en)).decode()


def des_decrypt(secretKey, content):
    """
    解密
    :param secretKey: 加密KEY
    :param content:   解密内容
    :return:
    """
    iv = secretKey
    k = des(secretKey, CBC, iv, pad=None, padmode=PAD_PKCS5)
    de = k.decrypt(binascii.a2b_hex(content), padmode=PAD_PKCS5)
    return de.decode()
